package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.Help;

@Stateless(name = "Help")
public class HelpEJBImpl implements IHelpLocal{

	@PersistenceContext(unitName = "PU_Cargaison")
	private EntityManager em;
	
	@Override
	public void addHelp(Help h) {
		em.persist(h);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Help> getAllHelp() {
		Query req=em.createQuery("select h from Help h");
		return req.getResultList();
	}

	@Override
	public Help getHelp(Integer Id) {
		Help de=em.find(Help.class, Id);
		if(de==null)throw new RuntimeException("Help introuvable");
		return de;
	}

	@Override
	public void updateHelp(Help h) {
		em.merge(h);
	}


	@Override
	public void deleteHelp(Integer Id) {
		Help h=getHelp(Id);
		em.remove(h);
	}

}
